<html>
<head><meta charset="utf-8"><title>How to get mut borrow from RefMut · general · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/index.html">general</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20mut.20borrow.20from.20RefMut.html">How to get mut borrow from RefMut</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="238556971"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20mut%20borrow%20from%20RefMut/near/238556971" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> will hunt <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20mut.20borrow.20from.20RefMut.html#238556971">(May 12 2021 at 23:04)</a>:</h4>
<p>My problem is same as <a href="https://www.reddit.com/r/rust/comments/8i02gw/refmut_and_normal_mut_borrow_polymorphism/">this</a>, I have a RefCell&lt;T&gt; and want get a &amp;mut T.</p>



<a name="238557276"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20mut%20borrow%20from%20RefMut/near/238557276" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20mut.20borrow.20from.20RefMut.html#238557276">(May 12 2021 at 23:07)</a>:</h4>
<p>Your problem is under specified. Based on what you have literally said, <a href="https://doc.rust-lang.org/std/cell/struct.RefCell.html#method.get_mut">https://doc.rust-lang.org/std/cell/struct.RefCell.html#method.get_mut</a> would solve your problem. I can almost guarantee that it’s not what you want (because of the under specification)</p>



<a name="238557379"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20mut%20borrow%20from%20RefMut/near/238557379" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20mut.20borrow.20from.20RefMut.html#238557379">(May 12 2021 at 23:08)</a>:</h4>
<p>The Discord is a better place for introductory questions like this as more people will be around to help you.</p>



<a name="238557458"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20mut%20borrow%20from%20RefMut/near/238557458" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20mut.20borrow.20from.20RefMut.html#238557458">(May 12 2021 at 23:09)</a>:</h4>
<p><a href="https://stackoverflow.com/q/45674479/155423">https://stackoverflow.com/q/45674479/155423</a></p>



<a name="238558140"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20mut%20borrow%20from%20RefMut/near/238558140" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20mut.20borrow.20from.20RefMut.html#238558140">(May 12 2021 at 23:17)</a>:</h4>
<p>And <a href="https://stackoverflow.com/q/29401626/155423">https://stackoverflow.com/q/29401626/155423</a></p>



<a name="238558248"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20mut%20borrow%20from%20RefMut/near/238558248" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20mut.20borrow.20from.20RefMut.html#238558248">(May 12 2021 at 23:18)</a>:</h4>
<p>Your title says RefMut and your prose says refcell</p>



<a name="238558298"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20mut%20borrow%20from%20RefMut/near/238558298" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20mut.20borrow.20from.20RefMut.html#238558298">(May 12 2021 at 23:19)</a>:</h4>
<p>Also <a href="https://doc.rust-lang.org/std/cell/struct.RefCell.html#method.borrow_mut">https://doc.rust-lang.org/std/cell/struct.RefCell.html#method.borrow_mut</a></p>



<a name="238563004"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20mut%20borrow%20from%20RefMut/near/238563004" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> will hunt <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20mut.20borrow.20from.20RefMut.html#238563004">(May 13 2021 at 00:13)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116155">Jake Goulding</span> <a href="#narrow/stream/122651-general/topic/How.20to.20get.20mut.20borrow.20from.20RefMut/near/238557276">said</a>:</p>
<blockquote>
<p>Your problem is under specified. Based on what you have literally said, <a href="https://doc.rust-lang.org/std/cell/struct.RefCell.html#method.get_mut">https://doc.rust-lang.org/std/cell/struct.RefCell.html#method.get_mut</a> would solve your problem. I can almost guarantee that it’s not what you want (because of the under specification)</p>
</blockquote>
<p>sorry about that, I created a new <a href="https://play.rust-lang.org/?version=stable&amp;mode=debug&amp;edition=2018&amp;gist=c3a8bc7d7208e1e28f0198ab44ae1ef3">playground</a>, I want to implement <code>Defef</code> and <code>DerefMut</code> for <code>FooRef</code>.</p>



<a name="238591654"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/122651-general/topic/How%20to%20get%20mut%20borrow%20from%20RefMut/near/238591654" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/122651-general/topic/How.20to.20get.20mut.20borrow.20from.20RefMut.html#238591654">(May 13 2021 at 07:44)</a>:</h4>
<p>You can't implement <code>Deref</code> and <code>DerefMut</code> for <code>FooRef</code> as <code>RefCell</code> needs a guard (<code>Ref</code> or <code>RefMut</code>) to be alive for the duration of the borrow to ensure that the borrow flag inside the <code>RefCell</code> is properly updated. Neither <code>Deref</code> nor <code>DerefMut</code> allows returning this guard.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>